<!--
 * @version: 
 * @Author: yu
 * @Date: 2023-07-06 16:21:21
 * @LastEditors: Andy
 * @LastEditTime: 2023-07-13 15:23:24
-->
<template>
    <div class="common-layout">
        <el-container>
            <el-aside width="170px">
                <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo"
                    :default-active="defaultActive" router collapse-transition text-color="#fff" unique-opened>
                    <el-menu-item index="/index/home">
                        <el-icon>
                            <Menu />
                        </el-icon>
                        <span>首 页</span>
                    </el-menu-item>
                    <!-- 动态绑定 -->
                    <!-- <template v-if="store.getters['user']">
                        <template v-for="item in store.getters['user'].menus">
                            <el-submenu v-if="item.children" :key="item.id" :index="item.title">
                                <template slot="title">
                                    <i :class="item.icon"></i>
                                    <span>{{ item.title }}</span>
                                </template>
                                <el-menu-item v-for="i in item.children" :key="i.id" :index="'/index/' + i.url">{{ i.title
                                }}</el-menu-item>
                            </el-submenu>
                            没有children字段的
                            <el-menu-item v-else  :index="'/index/' + item.url">{{ item.title
                            }}</el-menu-item>
                        </template>
                    </template> -->


                    <el-sub-menu index="1">
                        <template #title>
                            <el-icon>
                                <Setting />
                            </el-icon>
                            <span>系统管理</span>
                        </template>
                        <el-menu-item index="/index/menu">菜单管理</el-menu-item>
                        <el-menu-item index="/index/role">角色管理</el-menu-item>
                        <el-menu-item index="/index/member">管理员管理</el-menu-item>
                    </el-sub-menu>

                    <el-sub-menu index="3">
                        <template #title>
                            <el-icon>
                                <GoodsFilled />
                            </el-icon>
                            <span>商城管理</span>
                        </template>
                        <el-menu-item index="/index/cate">商品分类</el-menu-item>
                        <el-menu-item index="/index/specs">商品规格</el-menu-item>
                        <el-menu-item index="/index/goods">商品管理</el-menu-item>
                    </el-sub-menu>
                </el-menu>
            </el-aside>
            <el-container>
                <el-header>
                    <span>{{ store.getters['user'].username }}</span>
                    <el-button @click="quit" type="success">退出</el-button>
                </el-header>
                <el-main>
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>
<script setup>
import { useRoute, useRouter, currentRoute } from 'vue-router'
import { toRefs, reactive, onMounted } from 'vue'
import { useStore } from 'vuex'
import { ElMessage } from "element-plus";

const route = useRoute()
const router = useRouter()

const store = useStore()
let { defaultActive } = toRefs(reactive({
    defaultActive: '/home'
}))

const quit = () => {
    // //清除缓存
    store.dispatch('userActions', null)
    ElMessage.success('退出成功')
    // //路由跳转
    router.push('/login')
}


onMounted(() => {
    defaultActive.value = route.path
    // console.log(defaultActive);
    // console.log(route.path);
})




</script>
<style scoped>
.el-header {
    background-color: #B3C0D1;
    color: #333;
    text-align: right;
    line-height: 60px;
}

.el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
    height: 100vh;
}

.el-main {
    background-color: #E9EEF3;
    color: #333;
}
</style>